#include <iostream>
#include <string> 
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>

#include "../MsgBuffer.hpp"
#include "../ClientSession.hpp"

void do_query(ClientSession* this_,std::string& input, int id)
{
	//query(input, output);

	boost::shared_ptr<std::string> output(new std::string("hello"));
	std::cout << "input : " << input << std::endl;
	std::cout << "output : " << *output << std::endl;

	this_->write(output, id);
}

int main(int argc, char* argv[])
{
	try
	{
		if (argc < 4)
		{
		  std::cerr << "Usage: POIDB_server <host> <port> <server_name>\n";
		  return 1;
		}

		boost::asio::io_service io_service;

		tcp::resolver resolver(io_service);
		tcp::resolver::query query(argv[1], argv[2]);
		tcp::resolver::iterator iterator = resolver.resolve(query);

		printf("server name:%s\n", argv[3]);
		ClientSession sc(io_service, iterator, std::string(argv[3]));

		sc.regist_process(do_query);
		

		io_service.run();
	}
	catch(...)
	{

	}
}